package day1211_2;

class Pool{}

class  Lisi extends  Thread{
    Pool  pool;
    public void run() {//模拟张三给Pool中存水
        synchronized (pool){
            try {
                pool.wait();//取水的李四先等待水池放满水，再执行取水的代码
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("从水池对象"+pool+"中抽出水");
            System.out.println("从水池对象"+pool+"中抽出水");
        }
    }
}


class  ZhangSan extends  Thread{
    Pool  pool;
    public void run() {//模拟张三给Pool中存水
        synchronized (pool){
            System.out.println("用水池对象"+pool+"存水");
            System.out.println("用水池对象"+pool+"存水");
            pool.notify();
        }
    }
}


public class T2 {
    public static void main(String[] args) {
        Pool   pool=new Pool();

        ZhangSan  zs=new ZhangSan();
        zs.pool=pool;
        zs.start();

        Lisi   ls=new Lisi();
        ls.pool=pool;
        ls.start();
    }
}
